window.onload = function () {
    /**
     * 点击返回 跳转页面userInformation
     * 返回     removal
     */
    $('.removal').click(function () {
        window.location.href = "./userInformation.html";
    })

    /**
     * 弹出框的隐藏与显示
     * 添加按钮   add
     * 添加成功弹框   success-tip 、failure-tip
     */
    $(document).on('click', '.add', function (e) {
        var usersname = $('.userName').attr("value");
        var userPassword = $('.userPassword').attr("value");
        var userCompany = $('.userCompany').attr("value");
        var userProfession = $('.userProfession').attr("value");
        var userReturn = $('.userReturn').attr("value");
        // console.log(usersname)
        var data = {
            "userName": usersname,
            "password": userPassword,
            "company": userCompany,
            "job": userProfession,
            "isManager": userReturn
        }
        $.ajax({
            type: 'post',
            url: '/saveUser',
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success(data) {
                if (data == true) {
                    setTimeout(function () {
                        $('.success-tip').show();
                    }, 800);
                    setTimeout(function () {
                        $('.success-tip').hide();
                    }, 1800);
                    $('.userName').val('');
                    $('.userPassword').val('');
                    $('.userCompany').val('');
                    $('.userProfession').val('');
                    $('.userReturn').val('');


                } else {
                    setTimeout(function () {
                        $('.failure-tip').show();
                    }, 800);
                    setTimeout(function () {
                        $('.failure-tip').hide();
                    }, 1800);
                }
            }
        })
    })
    // $('.add').click(function () {
    //     setTimeout(function () {
    //         $('.success-tip').show();
    //     }, 800);
    //     setTimeout(function () {
    //         $('.success-tip').hide();
    //     }, 1800);
    // })


}